<?php


class QImageGallery extends QWebControl 
{
	protected $_images_list = array();
	
	public function init()
	{
		$this->setTemplate("gallery.tpl");
		$this->addCss("gallery.css");
	}
	
	public function addImage($src, $link = null, $caption = null, $html = null, $extra_class)
	{
		if (is_array($src))
			$this->_images_list[] = $src;
		else
			$this->_images_list[] = array("src" => $src, "link" => $link, "caption" => $caption, "html" => $html, "extra_class" => $extra_class);
		return $this->countImages() - 1;
	}
	
	public function countImages()
	{
		return count($this->_images_list);
	}
	
	public function getImageAt($pos)
	{
		if (isset($this->_images_list[$pos]))
			return $this->_images_list[$pos];
		else 
			return null;
	}
	
	public function removeAllImages()
	{
		unset($this->_images_list);
		$this->_images_list = array();
	}
	
	public function removeImageAt($pos)
	{
		if ($this->countImages() > $pos)
		{
			array_splice($this->_images_list, $pos, 1);
			return true;
		}
		return false;
	}
	
	public function removeImage($src)
	{
		$c_imgs = $this->countImages();
		for ($i = 0; $i < $c_imgs; $i++)
		{
			if ($this->_images_list[$i]["src"] == $src)
			{
				unset($this->_images_list[$i]);
				return true;
			}
		}
		return false;
	}
}


?>